const { ipcMain } = require('electron');
const { systemPreferences } = require('electron');
const { desktopCapturer } = require('electron');

ipcMain.on('getScreenSource', (e) => {
  const premise = systemPreferences.getMediaAccessStatus('screen');
  if (premise === 'denied') {
    console.log('没有权限');
    systemPreferences.askForMediaAccess('camera');
  }
  desktopCapturer
    .getSources({
      types: ['window', 'screen'],
      fetchWindowIcons: true,
      thumbnailSize: {
        width: 800,
        height: 800
      }
    })
    .then(async (sources) => {
      try {
        e.sender.send('SET_SOURCE', sources);
      } catch (error) {}
    })
    .catch((err) => console.log(err));
});
export {};
